import 'package:flutter/material.dart';
import 'package:flutterproject/mvvm/base/base_state.dart';
import 'package:flutterproject/page/mine/children/my_group/controller/my_group_controller.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/app_bar_common.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class MyGroupPage extends BaseState<MyGroupController> {
  @override
  MyGroupController initController() => MyGroupController();

  @override
  Widget initView(BuildContext context) {
    return ColoredBox(
      color: Color(0xFFF6F6F6),
      child: Column(
        children: [
          AppBarCommon(
            title: "我的团队",
            bgColor: Color(0xFFEDC88B),
            leftColor: Colors.white,
            titleColor: Colors.white,
          ),
          Container(
            margin: MarginPaddingUtil.only(left: 25, right: 25, top: 35),
            width: Get.width,
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/image/ic_teambg.png'),
                fit: BoxFit.fill, // 完全填充
              ),
            ),
            child: Column(
              children: [
                35.heightBox,
                TextCommon(
                  "${controller.bean?.level ?? 0}",
                  size: 40.sp,
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                ),
                36.heightBox,
                TextCommon(
                  controller.getVIPLevel(),
                  size: 36.sp,
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                  lineHeight: 52.sp,
                ),
                Container(
                  margin: MarginPaddingUtil.fromLTRB(
                      left: 33, top: 6, right: 33, bottom: 24),
                  padding: MarginPaddingUtil.symmetric(vertical: 20),
                  decoration: BoxDecoration(
                    color: Color(0xFFE0B774),
                    borderRadius: BorderRadius.circular(20.radius),
                  ),
                  child: Row(
                    children: [
                      Expanded(
                        child: Column(
                          children: [
                            TextCommon(
                              "推荐好友",
                              size: 20.sp,
                              color: Colors.white,
                              lineHeight: 29.sp,
                            ),
                            TextCommon(
                              "${controller.bean?.shareNum ?? 0}",
                              size: 36.sp,
                              color: Colors.white,
                              lineHeight: 52.sp,
                            ),
                          ],
                        ),
                      ),
                      Container(
                        color: Color(0xFFB49055),
                        height: 44.width,
                        width: 2.width,
                      ),
                      Expanded(
                        child: Column(
                          children: [
                            TextCommon(
                              "团队业绩",
                              size: 20.sp,
                              color: Colors.white,
                              lineHeight: 29.sp,
                            ),
                            TextCommon(
                              "${controller.bean?.teamAmount ?? 0}",
                              size: 36.sp,
                              color: Colors.white,
                              lineHeight: 52.sp,
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          20.heightBox,
          Expanded(
            child: Container(
              width: Get.width,
              margin: MarginPaddingUtil.symmetric(vertical: 24, horizontal: 20),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(20.radius),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(
                    padding: MarginPaddingUtil.only(top: 30, left: 20),
                    child: TextCommon(
                      "直推信息",
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  27.heightBox,
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      TextCommon(
                        "序号",
                        size: 18.sp,
                        color: Color(0xFF707070),
                      ),
                      SizedBox(
                        width: 150.width,
                        child: TextCommon(
                          "账号/时间",
                          size: 18.sp,
                          color: Color(0xFF707070),
                          align: TextAlign.center,
                        ),
                      ),
                      TextCommon(
                        "等级",
                        size: 18.sp,
                        color: Color(0xFF707070),
                      ),
                      SizedBox(
                        width: 120.width,
                        child: TextCommon(
                          "个人业绩",
                          size: 18.sp,
                          color: Color(0xFF707070),
                          align: TextAlign.center,
                        ),
                      ),
                      SizedBox(
                        width: 150.width,
                        child: TextCommon(
                          "团队业绩",
                          size: 18.sp,
                          color: Color(0xFF707070),
                          align: TextAlign.center,
                        ),
                      ),
                    ],
                  ),
                  12.heightBox,
                  Divider(
                    color: Color(0xFFE3E3E3),
                    height: 1.width,
                  ),
                  16.heightBox,
                  Expanded(
                    child: ListView.separated(
                      padding: EdgeInsets.zero,
                      shrinkWrap: true,
                      itemCount: controller.bean?.children?.length ?? 0,
                      separatorBuilder: (context, index) => Padding(
                        padding: MarginPaddingUtil.symmetric(vertical: 16),
                        child: Divider(
                          color: Color(0xFFE3E3E3),
                          height: 1.width,
                        ),
                      ),
                      itemBuilder: (context, index) => Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          TextCommon(
                            (index + 1).toString().padLeft(3, "0"),
                            size: 18.sp,
                            color: Color(0xFF707070),
                          ),
                          SizedBox(
                            width: 150.width,
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                TextCommon(
                                  "${controller.bean?.children![index].mobile}",
                                  size: 24.sp,
                                  lineHeight: 35.sp,
                                ),
                                6.heightBox,
                                TextCommon(
                                  DateFormat("yyyy-MM-dd HH:mm:ss").format(
                                      DateTime.fromMillisecondsSinceEpoch(
                                          controller.bean?.children![index]
                                                  .createTime ??
                                              0)),
                                  size: 16.sp,
                                  lineHeight: 26.sp,
                                  color: Color(0xFF707070),
                                ),
                              ],
                            ),
                          ),
                          TextCommon(
                            "V${controller.bean?.children![index].level}",
                            size: 24.sp,
                            color: Color(0xFF707070),
                          ),
                          SizedBox(
                            width: 120.width,
                            child: TextCommon(
                              "${controller.bean?.children![index].myAmount}",
                              size: 24.sp,
                              align: TextAlign.center,
                            ),
                          ),
                          SizedBox(
                            width: 150.width,
                            child: TextCommon(
                              "${controller.bean?.children![index].teamAmount}",
                              size: 24.sp,
                              align: TextAlign.center,
                            ),
                          ),
                        ],
                      ),
                    ),
                  )
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
